#ifndef __BASE_CONF_INCLUDE__
#define __BASE_CONF_INCLUDE__

#include <string>
#include <map>

using namespace std;

class BaseConfig {
public:
  BaseConfig() {};
  ~BaseConfig() {};

  bool Init(const char *filename);
  const char *GetStringValue(const char *key,
                             const char *default_val=NULL) const {
    map<string, string>::const_iterator it = kv_map_.find(key);
    if (it != kv_map_.end()) {
      return it->second.c_str();
    }
    return default_val;
  }

  int GetIntValue(const char *key, int default_val) const {
    const char *v = GetStringValue(key);
    return v ? atoi(v) : default_val;
  }

protected:
  virtual void ParseLine(const char *buf);
  virtual void GotKeyVal(const char *k, const char *v) {
#ifdef DEBUG
    fprintf(stderr, "%s -> %s\n", k, v);
#endif
  }
  virtual void GotKeyValMap(const map<string, string> &kv_map) {}

private:
  string filename_;
  map<string, string> kv_map_;
};

#endif

